home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / gnulib / libsrc98.zoo / getcwd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-09  |  1.1 KB  |  54 lines

  1. #include <stddef.h>
  2. #include <stdlib.h>    /* both of these added for malloc() */
  3. #include <stdio.h>
  4. #include <errno.h>
  5. #include <osbind.h>
  6. #include <unistd.h>
  7. #include <support.h>
  8.  
  9. /*******************************************************************
  10. getcwd: returns current working directory. By ERS.
  11. This routine is in the public domain.
  12. ********************************************************************/
  13.  
  14. char *getcwd __PROTO((char *, int));
  15.  
  16. char *getcwd(buf, size)
  17. char *buf; int size;
  18. {
  19.     volatile char path[FILENAME_MAX];
  20.     char drv;
  21. #ifndef __STDC__
  22.     extern char *malloc();
  23. #else
  24.     void *malloc(size_t);
  25. #endif
  26.  
  27.     if (!buf)
  28.         if ((buf = (char *) malloc((size_t)size)) == 0)
  29.             return NULL;
  30.     path[2] = '\0';
  31.     (void)Dgetpath(path+2, 0);
  32.     drv = Dgetdrv();
  33.     path[0] = drv + 'A';
  34.     path[1] = ':';
  35. #if 0    /* most programs will be happier without the extra slash */
  36.     if (!path[2]) {
  37.         path[2] = '\\';
  38.         path[3] = '\0';
  39.     }
  40. #endif
  41.     _full_dos2unx(path, buf);    /* convert DOS filename to unix */
  42.     return buf;
  43. }
  44.  
  45. /*
  46.  * char *getwd(char *buf)
  47.  *    return cwd in buf
  48.  */
  49. char *getwd(buf)
  50. char *buf;
  51. {
  52.     return getcwd(buf, FILENAME_MAX);
  53. }
  54.